package com.xue;

import cn.hutool.core.util.StrUtil;

import java.io.IOException;

/**
 * @author xuejingbao
 * @create 2023-10-16 下午 14:44
 */
public enum Config {

    INSTANCE;

    private String host = "tcp://192.168.0.158:1884";

    private String clientId = "xiaoche1";

    private final String userName = "admin";

    private final String password = "admin123";

    private String topic = "/hguwb_to_gps/conversion_coordinates/89697";

    public Config loadConfig(String[] args) throws IOException {
        for (int i = 0; i < args.length; i++) {
            String argItem = args[i];
            if ("--host".equals(argItem)) {
                i++;
                host = args[i];
            } else if ("--clientId".equals(argItem)) {
                i++;
                clientId = args[i];
            } else if ("--topic".equals(argItem)) {
                i++;
                topic = topic.replaceFirst("89697", args[i]);
            }
        }
        System.out.println(StrUtil.format(
                "配置信息读取完成:" +
                        "\nmqtt的Host地址:{}，" +
                        "\nmqtt的ClientId:{}，" +
                        "\nmqtt的topic:{}，", host, clientId, topic
        ));
        return this;
    }

    public String getHost() {
        return host;
    }

    public String getClientId() {
        return clientId;
    }

    public String getUserName() {
        return userName;
    }

    public String getPassword() {
        return password;
    }

    public String getTopic() {
        return topic;
    }
}
